package apiPractice;

import java.io.*;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;

public class Test06 {
    public static void main(String[] args) throws IOException {
        //统计一个文件calcCharNum.txt
        //（自己先往里面写一些内容，包含A以及a）
        //中字母 'A' 和 'a' 出现的总次数
        FileOutputStream fos = new FileOutputStream("calcCharNum.txt");
        FileInputStream fis = new FileInputStream("calcCharNum.txt");
        OutputStreamWriter osw = new OutputStreamWriter(fos, StandardCharsets.UTF_8);
        InputStreamReader isr = new InputStreamReader(fis, StandardCharsets.UTF_8);
        osw.write("sadsadwfsadwASDSADAASDwdsadwa");
        osw.close();//关流,否则无法进行剩下操作
        int d;
        int times = 0;//计算a和A出现的次数
        while ((d = isr.read()) != -1) {
            System.out.print((char) d);
            if ((char) d == 'a' || (char) d == 'A') {//读取的字符是A或者a
                times++;
            }
        }
        System.out.println();
        System.out.println("a和A一共出现了" + times+"次");
        isr.close();//关流


    }
}
